<template>
    <div class="news">
        <!-- 导航区 -->
        <ul>
            <li v-for="v in newList" :key="v.id">
                <!--第一种写法，to后面的是模板字符串-->
                <!-- <RouterLink :to="`/news/detail/${v.id}/${v.title}/${v.content}`">
                    {{ v.title }}
                </RouterLink>  -->
                <!--第二种写法，传递`params`参数时，若使用`to`的对象写法，必须使用`name`配置项，不能用`path`-->
                <button @click="showDetail(v)">查看新闻</button>
                <RouterLink :to="{
                    name: 'newDetail',
                    params: {
                        id: v.id,
                        title: v.title,
                        // content: v.content
                    }
                }">
                    {{ v.title }}
                </RouterLink>
            </li>
        </ul>
        <!--展示区-->
        <div class="news-content">
            <RouterView />
        </div>
    </div>


</template>

<script setup lang="ts" name="News">
import { reactive } from 'vue';
import { useRouter } from 'vue-router';

const newList = reactive([{
    id: 1,
    title: '新闻001',
    content: '新闻001的内容'
}, {
    id: 2,
    title: '新闻002',
    content: '新闻002的内容'
}, {
    id: 3,
    title: '新闻003',
    content: '新闻003的内容'
}]);

interface News {
    id: number,
    title: string,
    content: string
}

const router = useRouter();
function showDetail(v: News) {
    router.push({
        name: 'newDetail',
        params: {
            id: v.id,
            title: v.title,
            // content: v.content
        }
    });
}

</script>

<style scoped>
/* 新闻 */
.news {
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    height: 100%;
}

.news ul {
    margin-top: 30px;
    list-style: none;
    padding-left: 10px;
}

.news li>a {
    font-size: 18px;
    line-height: 40px;
    text-decoration: none;
    color: #64967E;
    text-shadow: 0 0 1px rgb(0, 84, 0);
}

.news-content {
    width: 70%;
    height: 90%;
    border: 1px solid;
    margin-top: 20px;
    border-radius: 10px;
}
</style>